//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//

//
#include "RecoveryAddressGeneratorGPGPU.h"

#include "GenRequest.h"
#include "VmMapper.h"

using namespace std;

/*!
  \file RecoveryAddressGeneratorGPGPU.cc
  \brief GPGPU specific code supporting generating addresses to use for recovery operations such as in fault handlers or register reloading.
*/

namespace Green {

  RecoveryAddressGeneratorGPGPU::RecoveryAddressGeneratorGPGPU(const Generator* pGenerator)
    : RecoveryAddressGenerator(pGenerator)
  {
  }

  const GenPageRequest* RecoveryAddressGeneratorGPGPU::CreateGenPageRequest(cbool isInstr, const EMemAccessType memAccessType) const
  {
    const VmMapper* vm_mapper  = GetCurrentVmMapper();

    // In a previous version, we attempted to avoid page faults altogether, which is too heavy handed. If the current
    // logic causes failures, we will revisit it, but we are not presently enforcing faultless recovery address
    // generation by default.
    GenPageRequest* page_req = vm_mapper->GenPageRequestRegulated(isInstr, memAccessType);

    page_req->SetGenAttributeValue(EPageGenAttributeType::Invalid, 0);  // Ensure Invalid attribute is set to 0.

    return page_req;
  }

}
